package model

import (
	"context"
	"fmt"
	"github.com/zeromicro/go-zero/core/stores/mon"
	"go.mongodb.org/mongo-driver/bson"
	"go.mongodb.org/mongo-driver/bson/primitive"
)

var _ LargeModelModel = (*customLargeModelModel)(nil)

type (
	// LargeModelModel is an interface to be customized, add more methods here,
	// and implement the added methods in customLargeModelModel.
	LargeModelModel interface {
		largeModelModel
		FindAll(ctx context.Context) ([]LargeModel, error)
		UpdateDeepSeek(ctx context.Context, id string, seek IDeepSeek) error
		UpdateKiMi(ctx context.Context, id string, mi IKiMi) error
		UpdateOther(ctx context.Context, id string, model *LargeModel) error
	}

	customLargeModelModel struct {
		*defaultLargeModelModel
	}
)

func (c customLargeModelModel) UpdateOther(ctx context.Context, id string, model *LargeModel) error {
	oid, err := primitive.ObjectIDFromHex(id)
	if err != nil {
		return ErrInvalidObjectId
	}
	_, err = c.conn.UpdateOne(ctx, bson.D{{"_id", oid}}, bson.M{"$set": bson.M{"type": model.Type, "number": model.Number, "nickName": model.NickName}})
	return err
}

func (c customLargeModelModel) UpdateDeepSeek(ctx context.Context, id string, seek IDeepSeek) error {
	oid, err := primitive.ObjectIDFromHex(id)
	if err != nil {
		return ErrInvalidObjectId
	}
	_, err = c.conn.UpdateOne(ctx, bson.D{{"_id", oid}}, bson.M{"$set": bson.M{"deepSeek": seek}})
	return err
}

func (c customLargeModelModel) UpdateKiMi(ctx context.Context, id string, mi IKiMi) error {
	oid, err := primitive.ObjectIDFromHex(id)
	if err != nil {
		return ErrInvalidObjectId
	}
	_, err = c.conn.UpdateOne(ctx, bson.D{{"_id", oid}}, bson.M{"$set": bson.M{"kiMi": mi}})
	return err
}

func (c customLargeModelModel) FindAll(ctx context.Context) ([]LargeModel, error) {
	var largemodels []LargeModel
	c.conn.Find(ctx, &largemodels, bson.D{})
	fmt.Println(largemodels)
	return largemodels, nil
}

// NewLargeModelModel returns a model for the mongo.
func NewLargeModelModel(url, db, collection string) LargeModelModel {
	conn := mon.MustNewModel(url, db, collection)
	return &customLargeModelModel{
		defaultLargeModelModel: newDefaultLargeModelModel(conn),
	}
}
